import { applyMiddleware, createStore, compose } from 'redux';

import thunkMiddleware from 'redux-thunk';
import reducers from '../reducers';

function configureStore() {
    const middlewares = [
        thunkMiddleware
    ];

    // In development, use the browser's Redux dev tools extension if installed
    const enhancers = [];
    const isDevelopment = process.env.NODE_ENV === 'development';
    if (isDevelopment && typeof window !== 'undefined' && window.window.__REDUX_DEVTOOLS_EXTENSION__) {
        enhancers.push(window.window.__REDUX_DEVTOOLS_EXTENSION__());
    }

    return createStore(
        reducers,
        undefined,
        compose(applyMiddleware(...middlewares), ...enhancers)
    );
}

export default configureStore;
